<template>
  <div class="app-container">
    <el-dialog
      :title="title"
      :visible.sync="openDetail"
      @close="cancel"
      width="600px"
      append-to-body
    >
      <el-form ref="formA" :model="form" :rules="rules" label-width="auto" style="width: 500px;">
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="规格型号" prop="productSpec">
          <el-input v-model="form.productSpec" placeholder="请输入规格型号" />
        </el-form-item>
        <!-- <el-form-item label="所属工序" prop="workSequenceCode">
          <el-select v-model="form.workSequenceCode" placeholder="请选择工序名称">
            <el-option
              v-for="item in processCodeList"
              :key="item.processId"
              :label="item.processName+'('+item.processCode+')'"
              :value="item.processCode"
            ></el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import {
  updateStationCheckConf,
  addStationCheckConf
} from "@/api/mes/pro/inspection";

export default {
  data() {
    return {
      openDetail: false,
      title: "新增产品",
      // 表单参数
      form: {},
      loading: false,
      routeproductbomList: [],
      checkTemplateId:null,
      // 选中数组
      ids: [],
      //物料编码
      itemCodes: [],
      measureCodes: [],
      //批量打印
      selectionList: [],
      processCodeList: [],
      rules: {
        workSequenceCode: [
          { required: true, message: "所属工序不能为空", trigger: "change" }
        ],
        checkItem: [
          { required: true, message: "检测项目不能为空", trigger: "blur" }
        ],
      }
    };
  },
  dicts: ["mes_order_status"],
  methods: {
    //初始化函数
    init(row, data) {
      // this.getprocessList();
      console.log(row, data, "子组件的row");
      let query = {};
      this.checkTemplateId = row.id;
      this.form = { ...data};
      this.openDetail = true;
      console.log(this.form, "=========form-======");
    },
    //获取工序编码list
    // getprocessList() {
    //   let query = {
    //     pageNum: 1,
    //     pageSize: 999,
    //   }
    //   processList(query).then(res => {
    //     console.log(res, "工序编码list");
    //     this.processCodeList = res.rows;
    //   });
    // },

    // 取消按钮
    cancel() {
      this.openDetail = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        checkTemplateId: null,
        checkItem:null,
        workSequenceName:null,
        workSequenceCode:null,
      };
      // this.checkTemplateId = null
      this.autoGenFlag = false;
      this.resetForm("formA");
    },
    submitForm() {
      this.form.checkTemplateId = this.checkTemplateId
      console.log(this.form, this.checkTemplateId,"=====qq=q=q=q=q====");
      let obj = this.processCodeList.filter(_=> _.processCode === this.form.workSequenceCode)
      if(obj && obj.length>0){
        this.form.workSequenceName = obj[0].processName
      }
      this.$refs["formA"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStationCheckConf(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openDetail = false;
              this.$emit("parentList");
            });
          } else {
            addStationCheckConf(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openDetail = false;
              this.$emit("parentList");
            });
          }
        }
      });
    }
  }
};
</script>
  <style rel="stylesheet/scss" lang="scss" scoped>
.app-container ::v-deep .el-drawer__header {
  padding-top: 10px !important;
  padding-bottom: 5px !important;
  margin-bottom: 10px !important;
}

.bg-purple {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    display: inline-block;
    // width: 100px;
    margin-right: 10px;
    white-space: nowrap;
    line-height: 30px;
  }
}
.titleDiv {
  font-weight: 700 !important;
  font-size: 20px;
}
</style>
  